<template>
  <a-spin :spinning="confirmLoading">
    <j-form-container :disabled="formDisabled">
      <a-form-model ref="form" :model="model" :rules="validatorRules" slot="detail">
        <a-row>
          <a-col :span="24">
            <a-form-model-item label="点位编码" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="tag">
              <a-input v-model="model.tag" placeholder="请输入点位编码"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="时间戳" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="time">
              <j-date placeholder="请选择时间戳" v-model="model.time"  style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="井名井号" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="name">
              <a-input v-model="model.name" placeholder="请输入井名井号"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="设备编号" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="serialNo">
              <a-input v-model="model.serialNo" placeholder="请输入设备编号"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="加注状态" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="fillStatus">
              <a-input-number v-model="model.fillStatus" placeholder="请输入加注状态" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="循环加注的循环时间" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="fillCycTime">
              <a-input-number v-model="model.fillCycTime" placeholder="请输入循环加注的循环时间" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="停泵时间" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="stopPumpTime">
              <a-input-number v-model="model.stopPumpTime" placeholder="请输入停泵时间" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="泵排量" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="pumpDisplacement">
              <a-input-number v-model="model.pumpDisplacement" placeholder="请输入泵排量" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="药剂配置比例" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="medicAllocProp">
              <a-input-number v-model="model.medicAllocProp" placeholder="请输入药剂配置比例" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="加入药剂量" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="fillMedicVol">
              <a-input-number v-model="model.fillMedicVol" placeholder="请输入加入药剂量" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="加注水量" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="fillWaterVol">
              <a-input-number v-model="model.fillWaterVol" placeholder="请输入加注水量" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="状态开始时间" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="statusStartTime">
              <j-date placeholder="请选择状态开始时间" v-model="model.statusStartTime"  style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="配液时间" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="liquidDispensingTime">
              <j-date placeholder="请选择配液时间" v-model="model.liquidDispensingTime"  style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="加注时间（制度）" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="fillTimeConf">
              <a-input-number v-model="model.fillTimeConf" placeholder="请输入加注时间（制度）" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="循环加注的循环时间（制度）" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="fillCycTimeConf">
              <a-input-number v-model="model.fillCycTimeConf" placeholder="请输入循环加注的循环时间（制度）" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="药剂配置比例（制度）" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="medicAllocPropConf">
              <a-input-number v-model="model.medicAllocPropConf" placeholder="请输入药剂配置比例（制度）" style="width: 100%" />
            </a-form-model-item>
          </a-col>
        </a-row>
      </a-form-model>
    </j-form-container>
  </a-spin>
</template>

<script>

  import { httpAction, getAction } from '@/api/manage'
  import { validateDuplicateValue } from '@/utils/util'

  export default {
    name: 'PpgyPpjzztsjForm',
    components: {
    },
    props: {
      //表单禁用
      disabled: {
        type: Boolean,
        default: false,
        required: false
      }
    },
    data () {
      return {
        model:{
         },
        labelCol: {
          xs: { span: 24 },
          sm: { span: 5 },
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 16 },
        },
        confirmLoading: false,
        validatorRules: {
        },
        url: {
          add: "/ppgyPpjzztsj/ppgyPpjzztsj/add",
          edit: "/ppgyPpjzztsj/ppgyPpjzztsj/edit",
          queryById: "/ppgyPpjzztsj/ppgyPpjzztsj/queryById"
        }
      }
    },
    computed: {
      formDisabled(){
        return this.disabled
      },
    },
    created () {
       //备份model原始值
      this.modelDefault = JSON.parse(JSON.stringify(this.model));
    },
    methods: {
      add () {
        this.edit(this.modelDefault);
      },
      edit (record) {
        this.model = Object.assign({}, record);
        this.visible = true;
      },
      submitForm () {
        const that = this;
        // 触发表单验证
        this.$refs.form.validate(valid => {
          if (valid) {
            that.confirmLoading = true;
            let httpurl = '';
            let method = '';
            if(!this.model.id){
              httpurl+=this.url.add;
              method = 'post';
            }else{
              httpurl+=this.url.edit;
               method = 'put';
            }
            httpAction(httpurl,this.model,method).then((res)=>{
              if(res.success){
                that.$message.success(res.message);
                that.$emit('ok');
              }else{
                that.$message.warning(res.message);
              }
            }).finally(() => {
              that.confirmLoading = false;
            })
          }
         
        })
      },
    }
  }
</script>